package com.pdd.commons.response;

import com.pdd.commons.enums.ResponseErrorEnum;
import com.pdd.commons.enums.ResponseSuccessEnum;

/**
 * @author:liyangpeng
 * @date:2018/12/7 15:01
 */
public class ResponseResult {

    public static ResponseEntity RETURN_SUCCESS(ResponseSuccessEnum responseEnum, String ...format){
        ResponseEntity entity=new ResponseEntity();
        entity.setCode(responseEnum.getCode());
        if(format!=null){
            entity.setMessage(String.format(responseEnum.getMessage(),format));
        }else{
            entity.setMessage(responseEnum.getMessage());
        }
        return entity;
    }

    public static ResponseEntity RETURN_SUCCESS(ResponseSuccessEnum responseSuccessEnum, Object data){
        ResponseEntity entity=new ResponseEntity();
        entity.setCode(responseSuccessEnum.getCode());
        entity.setMessage(responseSuccessEnum.getMessage());
        entity.setData(data);
        return entity;
    }

    public static ResponseEntity RETURN_ERROR(ResponseErrorEnum responseEnum, String ...format){
        ResponseEntity entity=new ResponseEntity();
        entity.setCode(responseEnum.getCode());
        if(format!=null){
            entity.setMessage(String.format(responseEnum.getMessage(),format));
        }else{
            entity.setMessage(responseEnum.getMessage());
        }
        return entity;
    }

    public static boolean IS_SUCCESS(ResponseEntity entity){
        if(entity.getCode().equals("0000")){
            return true;
        }
        return false;
    }

    public static ResponseEntity RETURN_SUCCESS(String message){
        ResponseEntity entity=new ResponseEntity();
        entity.setCode("0000");
        entity.setMessage(message);
        return entity;
    }

    public static ResponseEntity RETURN_ERROR(String message){
        ResponseEntity entity=new ResponseEntity();
        entity.setCode("0001");
        entity.setMessage(message);
        return entity;
    }
}
